package com.lucy.common.config;

import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
import com.lucy.common.module.plume.PlumeInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author kindear
 */
@Configuration
public class WebAppConfig implements WebMvcConfigurer {
    @Bean
    public PlumeInterceptor plumeInterceptor(){
        return new PlumeInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * sa-token 鉴权
         */
        registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
        /**
         * plumelog 鉴权
         */
        registry.addInterceptor(plumeInterceptor()).addPathPatterns("/plumelog/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");

    }
}
